import numpy as np
import scipy.io as scio
import pylab as pl
dataFile = '../clips/Patient_6/Patient_6_ictal_segment_29.mat';
data = scio.loadmat(dataFile);
#time domain data
x = [num for num in range(2501)];
#print x
y = data['data'][0];
# pl.plot(x,y)
# pl.title('EEG Time Domain Signal')
# pl.ylabel('Amplitude Values')
# pl.xlabel('Sampling Times')
# pl.show()



#frequency data
fft = np.fft.rfft(y)
fft = np.abs(fft)
print fft.shape
y=[]

fft = np.cumsum(fft)
for i in range(len(fft)):
	z=fft[i]/fft[2500]
	y.append(z)
pl.plot(x,y)
pl.title('Frequency Power Accumulate')
pl.ylabel('Power Percentage')
pl.xlabel('Frequency')
pl.show()


# return np.column_stack([fft[:,i] - fft[:,i-bin_size] 
#     for i in range(bin_size, max_freq, bin_size)])
bin_size = 10
max_freq = 2501
y=[]
for i in range(bin_size, max_freq, bin_size):
	z = fft[i] - fft[i-bin_size]
	y.append(z)
#y = np.column_stack([fft[:,i] - fft[:,i-bin_size] for i in range(bin_size, max_freq, bin_size)])

x = [num for num in range(250)]
pl.bar(x,y)
pl.title('Per 10HZ Power Accumulate')
pl.ylabel('Amplitude Values')
pl.xlabel('Per 10Hz')
pl.show()


bin_size = 10
max_freq = 251
y=[]
for i in range(bin_size, max_freq, bin_size):
	z = (fft[i] - fft[i-bin_size])/fft[2500]
	y.append(z)
#y = np.column_stack([fft[:,i] - fft[:,i-bin_size] for i in range(bin_size, max_freq, bin_size)])

x = [num for num in range(25)]
pl.bar(x,y)
pl.title('Per 10HZ Power Accumulate(0~250)')
pl.ylabel('Power Percentage')
pl.xlabel('Per 10Hz')
pl.show()